package org.qpcr.community.device.message.writer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.qpcr.community.device.service.data.DeviceDataService;
import org.qpcr.community.gateway.annotation.Subscribe;
import org.qpcr.core.message.DeviceMessage;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Random;

/**
 * 用于将设备消息写入到时序数据库
 *
 * @author zhouhao
 * @since 1.0
 */
@Slf4j
@RequiredArgsConstructor
public class TimeSeriesMessageWriterConnector {
    private final DeviceDataService dataService;


    /**
     * 订阅设备消息 入库
     *
     * @param message 设备消息
     * @return void
     */
    @Subscribe(topics = "/device/**", id = "device-message-ts-writer")
    public Mono<Void> writeDeviceMessageToTs(DeviceMessage message) {
        return dataService.saveDeviceMessage(message);
    }


    public static void main(String[] args) {


//        int randomDigits = 10; // 假设我们想要10位随机数
//        Random random = new Random();
//
//        // 生成随机整数，注意这里的范围是[0, 10^digits)，不包括10^digits
//        int randomNumber = random.nextInt((int) Math.pow(10, 3));
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("mmss");

        // 格式化时间
        String formattedDateTime = now.format(formatter);

        // 打印格式化后的时间
        System.out.println(formattedDateTime);




        System.out.println(now.toString());

    }

}
